package jse.test20160615.reflect;

import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.text.Annotation;

import org.junit.Test;

/**
 * @desc	java反射机制得到 类的修饰信息、接口，参数等 
 * @author kanggw
 * @datetime 2016年6月15日,下午8:40:46
 */
public class Reflect {

	@Test
	public void test() throws ClassNotFoundException {
		
		Class<?> clazz = Class.forName("java.util.ArrayList");
		System.out.println("类的标准名称："+clazz.getCanonicalName());
		System.out.println("类的修饰符:"+Modifier.toString(clazz.getModifiers()));
		System.out.println("输入类型的参数");
		TypeVariable<?>[]  variables = clazz.getTypeParameters();
		if(variables.length != 0) {
			for(TypeVariable<?> variable : variables ) {
				System.out.println(variable+"\t");
			}
		}else {
			System.out.println("空");
		}
		
		//接口
		Type[] intefaces =  clazz.getGenericInterfaces();
		if(intefaces.length != 0) {
			for(Type  inter : intefaces) {
				System.out.println("\t"+inter);
			}
		} else {
			System.out.println("空");
		}
		
		Type superClass = clazz.getGenericSuperclass();
		System.out.println("直接继承类");
		
		if(superClass != null ) {
			System.out.println(superClass);
		} else {
			System.out.println("空");
		}
		
		java.lang.annotation.Annotation[]	annotations = clazz.getAnnotations();
		if(annotations.length != 0) {
			for(java.lang.annotation.Annotation annotation : annotations) {
				System.out.println("注释信息"+annotation);
			}
		} else {
			System.out.println("空");
			
		}
		
	}
}
